<template>
	<view class="content">
		<official-account></official-account>
		<sklelton v-if="loading"></sklelton>
		<view class="" v-else>
			<view class="top">
				<image class="bcg" src="/static/ibcg.png" mode=""></image>
				<view class="navbar" :style="`top: ${top}px; width: calc(100% - ${rightIcon}px)`">
					<view class="navbar_l flex_jc_sb" @click="gochangecity">
						<uni-icons type="location-filled" size="24" color="#75613E"></uni-icons>
						<view class="text">{{ data.city }}</view>
						<image class="down" src="/static/down.png" mode=""></image>
					</view>
					<view class="navbar_r flex_jc_cent" @click="$pageGo('/pages/activity/searchActivity')">
						<image src="/static/search.png" mode=""></image>
					</view>
				</view>
				<view class="block_1" :style="{ top: top + 'px' }">
					<view class="title">推荐活动</view>
					<view class="scroll-container">
						<scroll-view scroll-x="true" class="horizontal-scroll" show-scrollbar="false">
							<view class="scroll-content">
								<view class="scroll-item" v-for="(item, index) in data.topList" :key="index" @click="$pageGo(`/pages/activity/info?id=${item.id}`)">
									<image class="itembcg" :src="item.imgFace" mode="aspectFill" :lazy-load="true"></image>
									<view class="itemads">
										<view class="tit">{{ item.name }}</view>
										<view class="tip flex">
											<view class="t1">{{ item.type }}</view>
											<view class="t2" v-if="item.sign == '1'">签到</view>
											<view class="t2">{{ item.lineType == 1 ? '线上' : '线下' }}</view>
										</view>
										<view class="ttt flex">
											<image src="/static/i2.png" mode=""></image>
											<view class="">{{ $formatDateTime(item.beginTime) }}</view>
										</view>
										<view class="ttt flex" v-if="item.lineType == 1">
											<image src="/static/i3.png" mode=""></image>
											<view class="ts">{{ item.platform }}</view>
										</view>
										<view class="ttt flex" v-else>
											<image src="/static/i1.png" mode=""></image>
											<view class="ts">{{ item.addressInfo }}</view>
										</view>
									</view>
								</view>
							</view>
							<view class="kkk" v-if="data.topList.length == 0">
								<image src="https://www.daolangtongge.com/read-book-api/profile/mini_app/img/kk3.png" mode=""></image>
							</view>
						</scroll-view>
					</view>
				</view>
			</view>
			<view class="block_2">
				<view class="tit_flex flex_jc_sb">
					<view class="title">历史活动</view>
					<view class="rig flex" @click="gohistory">
						查看更多
						<uni-icons type="right" size="16" color="#75613E"></uni-icons>
					</view>
				</view>
				<view class="text_block flex_jc_cent">
					<view class="">
						<view class="">
							Hi，今天是「稻浪同歌」成立第
							<text>{{ dataInfo.day }}</text>
							天
						</view>
						<view class="">
							我们已经举办
							<text>{{ dataInfo.count }}</text>
							场活动，谢谢你
							<image src="/static/z.png" mode=""></image>
						</view>
					</view>
				</view>
				<view class="item" v-if="dataInfo.activity" @click="$pageGo(`/pages/activity/info?id=${dataInfo.activity.id}`)">
					<image :src="dataInfo.activity.imgFace" mode="aspectFill"></image>
					<view class="itemads">
						<view class="t_time flex">
							<view class="t1">{{ $formatTime(dataInfo.activity.beginTime, 'year') }} {{ $formatTime(dataInfo.activity.beginTime, 'month-day') }}</view>
							<view class="t"></view>
							<view class="t2">{{ $formatTime(dataInfo.activity.beginTime, 'week-day') }} {{ $formatTime(dataInfo.activity.beginTime, 'hours-minutes') }}</view>
						</view>
						<view class="b_1">{{ dataInfo.activity.name }}</view>
						<view class="b_2 flex" v-if="dataInfo.activity.lineType == 1">
							<image src="/static/i3.png" mode=""></image>
							<view class="texts">
								{{ dataInfo.activity.platform }}
							</view>
						</view>
						<view class="b_2 flex" v-else>
							<image src="/static/i1.png" mode=""></image>
							<view class="texts">
								{{ dataInfo.activity.addressInfo }}
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="b_button" @click="gohistory">查看更多历史活动</view>
		</view>
		<uni-popup ref="popupRef" type="center" :is-mask-click="false">
			<view class="props">
				<view class="">
					<image src="/static/nologn.png" mode=""></image>
				</view>
				<view class="tt">当前账号已违规，禁止登录</view>
			</view>
		</uni-popup>
		<uv-tabbar :value="0" class="tab"></uv-tabbar>
	</view>
</template>

<script setup>
import { toast, showConfirm, tansParams } from '@/utils/common';
import { getCurrentInstance, nextTick, reactive, ref } from 'vue';
import { onLoad, onShow, onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app';
import sklelton from '@/components/sklelton/index.vue';
import { login } from '@/api/login.js';
import { homeHistoryNew, homeHistoryData, homeHot } from '@/api/index.js';
// 获取全局方法
const { proxy } = getCurrentInstance();

const gohistory = () => {
	uni.navigateTo({
		url: '/pages/index/history'
	});
};
const gochangecity = () => {
	uni.navigateTo({
		url: '/mypage/changecity'
	});
};
const loading = ref(true);
// 开始做功能
import { getToken, setToken } from '@/utils/auth';
const top = ref(0);
const rightIcon = ref(0);
const popupRef = ref(null);
// 静默登录
const silentLogin = () => {
	loading.value = true;
	uni.login({
		provider: 'weixin', //使用微信登录
		success: function (loginRes) {
			login({ code: loginRes.code }).then((res) => {
				if (res.code == 200 && res.data.status) {
					setToken(res.data.token);
					top.value = uni.getStorageSync('topIcon');
					rightIcon.value = uni.getStorageSync('rightIcon');
					getListTwo();
					nextTick(() => {
						loading.value = false;
					});
				} else {
					uni.removeStorageSync('activity');
					uni.removeStorageSync('city');
					uni.removeStorageSync('App-Token');
					loading.value = false;
					popupRef.value.open();
				}
			});
		}
	});
};
const data = reactive({
	city: '西安市',
	topList: []
});
const dataInfo = reactive({});
// 历史活动
import { getData } from '@/api/login.js';
const getListTwo = () => {
	homeHistoryNew({}).then((res) => {
		if (res.code == 200) {
			Object.assign(dataInfo, res.data);
		}
	});
	homeHot({ city: data.city }).then((res) => {
		if (res.code == 200) {
			data.topList = res.data;
		}
	});
	getData({}).then((res) => {
		if (res.code == 200) {
			uni.setStorageSync('userData', res.data);
		}
	});
};
onPullDownRefresh(() => {
	getListTwo();
	uni.stopPullDownRefresh(); // 停止下拉刷新动画
});
onShow(() => {
	uni.$once('cityChange', function (e) {
		data.city = e.value;
		homeHot({ city: e.value }).then((res) => {
			if (res.code == 200) {
				data.topList = res.data;
			}
		});
	});
});
onLoad(() => {
	data.city = uni.getStorageSync('address').value;
	silentLogin();
});
</script>
<script>
export default {
	onShareAppMessage() {
		return {
			title: '欢迎使用稻浪同歌！',
			path: `pages/index/index`
		};
	},
	onShareTimeline() {
		return {
			title: '欢迎使用稻浪同歌！',
			path: `pages/index/index`
		};
	}
};
</script>
<style lang="scss">
page {
	background: #fbfcf9;
}
.kkk{
	width: 452rpx;
	height: 184rpx;
	margin-top: 58rpx;
	image{
		width: 452rpx;
		height: 184rpx;
	}
}
.props {
	width: 620rpx;
	height: 440rpx;
	background: linear-gradient(180deg, #ece6d5 0%, #f7f8f6 100%);
	border-radius: 20rpx 20rpx 20rpx 20rpx;
	padding: 90rpx 110rpx;
	box-sizing: border-box;
	text-align: center;
	image {
		width: 140rpx;
		height: 148rpx;
	}
	.tt {
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		font-size: 32rpx;
		color: #4e3f23;
		margin-top: 52rpx;
		
	}
}
.top {
	.bcg {
		width: 100%;
		height: 600rpx;
		position: relative;
	}
	.navbar {
		position: fixed;
		// height: 88rpx;
		// width: calc(100% - 94px);
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0rpx 20rpx 0rpx 15rpx;
		box-sizing: border-box;
		z-index: 2;
		.text {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #75613e;
		}
		.down {
			width: 24rpx;
			height: 18rpx;
			margin-left: 15rpx;
		}
		.navbar_r {
			width: 64rpx;
			height: 64rpx;
			background: rgba(0, 0, 0, 0.15);
			border-radius: 32rpx;
			image {
				width: 32rpx;
				height: 32rpx;
			}
		}
	}

	.block_1 {
		position: absolute;
		width: 100%;
		padding: 88rpx 0rpx 0rpx 20rpx;
		box-sizing: border-box;
		z-index: 1;
		.title {
			font-family: Source Han Serif CN, Source Han Serif CN;
			font-weight: bold;
			font-size: 40rpx;
			color: #75613e;
		}
		.scroll-container {
			width: 100%;
			padding: 20rpx 0rpx;
			box-sizing: border-box;
			/* 增加容器内边距 */
		}

		.horizontal-scroll {
			width: 100%;
			line-height: 1;
			-webkit-overflow-scrolling: touch;
		}

		.scroll-content {
			display: flex;
			flex-direction: row;
		}
		.scroll-item {
			width: 320rpx;
			height: 440rpx;
			margin-right: 20rpx;
			border-radius: 20rpx;
			position: relative;
			.itembcg {
				width: 320rpx;
				height: 440rpx;
				border-radius: 20rpx;
			}
			.itemads {
				position: absolute;
				width: 320rpx;
				height: 190rpx;
				border-radius: 0rpx 0rpx 20rpx 20rpx;
				bottom: 0%;
				background: rgba(0, 0, 0, 0.5);
				padding: 20rpx;
				box-sizing: border-box;
				.tit {
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 28rpx;
					color: #ffffff;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
				.tip {
					margin: 20rpx 0rpx 0rpx 0rpx;
					.t1 {
						padding: 0rpx 6rpx;
						height: 32rpx;
						background: #b19561;
						border-radius: 8rpx 8rpx 8rpx 8rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 20rpx;
						color: #ffffff;
						line-height: 32rpx;
						margin-right: 10rpx;
					}
					.t2 {
						padding: 0rpx 6rpx;
						height: 28rpx;
						border-radius: 8rpx 8rpx 8rpx 8rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 20rpx;
						color: #ffffff;
						line-height: 28rpx;
						border: 1px solid #ffffff;
						margin-right: 10rpx;
					}
				}
				.ttt {
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 20rpx;
					color: #ffffff;
					margin: 15rpx auto;
					image {
						width: 24rpx;
						height: 24rpx;
						margin-right: 10rpx;
					}
					.ts {
						flex: 1;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}
				}
			}
		}
	}
}
.block_2 {
	width: 710rpx;
	margin: 110rpx auto 28rpx;
	.tit_flex {
		.title {
			font-family: Source Han Serif CN, Source Han Serif CN;
			font-weight: bold;
			font-size: 40rpx;
			color: #75613e;
		}
		.rig {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 24rpx;
			color: #75613e;
		}
	}
	.text_block {
		width: 670rpx;
		height: 100rpx;
		background: #f5f5f0;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		margin: 20rpx auto;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 24rpx;
		color: #b19561;
		text-align: center;
		text {
			font-family: 'DIN-BOLD';
			font-size: 32rpx;
			font-weight: bold;
		}
		image {
			width: 22rpx;
			height: 28rpx;
			margin-left: 6rpx;
			margin-top: 10rpx;
		}
	}

	.item {
		width: 710rpx;
		height: 380rpx;
		border-radius: 20rpx;
		position: relative;
		image {
			width: 710rpx;
			height: 380rpx;
			border-radius: 20rpx;
		}
		.itemads {
			position: absolute;
			top: 0%;
			width: 710rpx;
			height: 380rpx;
			border-radius: 20rpx;
			padding: 24rpx 22rpx;
			box-sizing: border-box;
			background: rgba(0, 0, 0, 0.3);
			.t_time {
				.t1 {
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 12rpx;
					color: #ffffff;
					width: 32rpx;
					text-align: center;
				}
				.t2 {
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 20rpx;
					color: #ffffff;
				}
				.t {
					width: 4rpx;
					height: 24rpx;
					background: #b19561;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					margin: 0rpx 10rpx;
				}
			}
			.b_1 {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 28rpx;
				color: #ffffff;
				margin-top: 225rpx;
			}
			.b_2 {
				margin-top: 15rpx;
				image {
					width: 28rpx;
					height: 28rpx;
					margin-right: 10rpx;
				}
				.texts {
					flex: 1;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #ffffff;
				}
			}
		}
	}
}
.b_button {
	text-align: center;
	font-family: PingFang SC, PingFang SC;
	font-weight: 500;
	font-size: 24rpx;
	color: #75613e;
}
</style>
